package com.gbb.simple.base;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.fragment.app.Fragment;
import android.view.View;

public class BaseFragment extends Fragment {

    protected BaseFragmentActivity mContext;

    protected View rootView;

    @Override
    public void onAttach(Activity activity){
        mContext = (BaseFragmentActivity) activity;
        super.onAttach(activity);
    }

    public void startActivity(Class<? extends Activity> targetClass){
        startActivity(new Intent(mContext,targetClass));
    }

    public void startActivity(Intent intent,int enterResId,int exitResId){
        Bundle animBundle = ActivityOptionsCompat.makeCustomAnimation(mContext,enterResId,exitResId).toBundle();
        ActivityCompat.startActivity(mContext,intent,animBundle);
    }

    public void startActivity(Class<? extends Activity> targetClass,int enterResId,int exitResId){
        Bundle animBundle = ActivityOptionsCompat.makeCustomAnimation(mContext,enterResId,exitResId).toBundle();
        ActivityCompat.startActivity(mContext,new Intent(mContext,targetClass),animBundle);
    }

    protected void showToast(String toastContent){
        mContext.showToast(toastContent);
    }

    protected void showToast(int textId){
        mContext.showToast(textId);
    }

    protected void showLoadingDialog(String message){
        mContext.showLoadingDialog(message);
    }

    protected void closeLoadingDialog(){
        mContext.closeLoadingDialog();
    }

    public ProgressDialog getLoadingDialog(){
        return mContext.getLoadingDialog();
    }

}
